package com.lfg.leetcode.leetcode0;

/**
 *
 */
public class No11MaxArea {

    public static void main(String[] args) {
//        System.out.println(maxArea(new int[]{1,8,6,2,5,4,8,3,7}));
        System.out.println(maxArea2(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
    }

    public static int maxArea2(int[] height) {
        int ret = 0;
        int i = 0;
        int j = height.length - 1;
        while (j > i) {
            int area = Math.min(height[i], height[j]) * (j - i);
            ret = Math.max(area, ret);

            if (height[i] < height[j]) {
                i++;
            } else {
                j--;
            }
        }
        return ret;
    }

    public static int maxArea(int[] height) {
        int ret = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i + 1; j < height.length; j++) {
                int area = Math.min(height[i], height[j]) * (j - i);
                if (area > ret) {
                    ret = area;
                }
            }
        }
        return ret;
    }
}
